package com.yq.bdm.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.yq.bdm.utils.SysParamsConstants;

/**
 * 处理登录
 * @author Administrator
 *
 */
public class LoginInterceptor extends HandlerInterceptorAdapter {
	protected Logger logger = LoggerFactory.getLogger(getClass());
	
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
            Object handler) throws Exception{
		logger.info("被拦截了..........");
		
		//获取session里的登录状态值
		Object isLogin = request.getSession().getAttribute("isLogin");
	    //如果登录状态不为空则返回true，返回true则会执行相应controller的方法
	    if(isLogin != null){
	      return true;
	    }
	    //如果登录状态为空则重定向到登录页面，并返回false，不执行原来controller的方法
	    response.sendRedirect(SysParamsConstants.NAMESPACEURL + "login/");
	    return false;
	}
}
